//
//  CustomerBankCardSuc.m
//  HuoBao
//
//  Created by sky on 15/11/30.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CustomerBankCardSuc.h"



@interface CustomerBankCardSuc ()


@property (nonatomic, strong) UIView *dangban;
@property (nonatomic, strong) UIView *bgview;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, assign) NSInteger num;



@end

@implementation CustomerBankCardSuc



- (nonnull instancetype)initWithBankName:(NSString *)name withBankCard:(NSString *)ID{
    
    self = [super init];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    self.num = 0;
    
    self.dangban = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.dangban.backgroundColor = [UIColor blackColor];
    self.dangban.alpha = 0.3;
    [self addSubview:self.dangban];
        
        
    self.bgview = [[UIView alloc]initWithFrame:CGRectMake(35, SCREEN_HEIGHT/2 - 336/4 - 50, SCREEN_WIDTH - 70, 336/2 - 13)];
    self.bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
    self.bgview.alpha = 0;
    self.bgview.layer.cornerRadius = 4;
    [self addSubview:self.bgview];
        
    
    NSString *str = @"银行卡添加成功!";
    CGSize strsize = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:22]}];
    
    UIImage *duihao = [UIImage imageNamed:@"bank_suc"];
    UIImageView *duivi = [[UIImageView alloc]initWithFrame:CGRectMake(self.bgview.width/2 - (10 + strsize.width + duihao.size.width)/2 , 25, duihao.size.width, duihao.size.height)];
    duivi.image = duihao;
    [self.bgview addSubview:duivi];
    
    
    UILabel *titlelbl = [self LabelWithRect:CGRectMake(duivi.origin.x + duihao.size.width + 10, 59/2, 22 * 8, 22) textColor:[LCCommon getColor:@"ffffff"] textstr:@"银行卡绑定成功!" textfont:22 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:titlelbl];
    
    
    UILabel *banklbl = [self LabelWithRect:CGRectMake(30, duivi.origin.y + duihao.size.height + 23, 30, 13) textColor:[LCCommon getColor:@"888888"] textstr:@"银行:" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:banklbl];
    
    
    UILabel *namelbl = [self LabelWithRect:CGRectMake(banklbl.origin.x + 30 + 10, banklbl.origin.y, self.bgview.width - (banklbl.origin.x + 30 + 10), 13) textColor:[LCCommon getColor:@"b1b1b1"] textstr:name textfont:13 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:namelbl];
    
    
    UILabel *cardlbl = [self LabelWithRect:CGRectMake(30, namelbl.origin.y + 13 + 9, 30, 13) textColor:[LCCommon getColor:@"888888"] textstr:@"卡号:" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:cardlbl];
    
    
    UILabel *cardnum = [self LabelWithRect:CGRectMake(namelbl.origin.x , cardlbl.origin.y, namelbl.size.width, 13) textColor:[LCCommon getColor:@"b1b1b1"] textstr:ID textfont:13 textstyle:NSTextAlignmentLeft];
    [self.bgview addSubview:cardnum];
    
    
//    UILabel *tishi = [self LabelWithRect:CGRectMake(30, cardlbl.origin.y + 13 + 19, self.bgview.width - 30, 13) textColor:[LCCommon getColor:@"de7c2c"] textstr:@"资金需同卡进出,银行相关问题可联系客服" textfont:13 textstyle:NSTextAlignmentLeft];
//    [self.bgview addSubview:tishi];
    
    return self;
}

- (void)showInView
{

    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.bgview.backgroundColor = [LCCommon getColor:@"3d3e41"];
        self.bgview.alpha = 1;
    }completion:^(BOOL finished) {
      self.timer =[NSTimer scheduledTimerWithTimeInterval:0.2
                                               target:self
                                             selector:@selector(getResults)
                                             userInfo:nil
                                              repeats:YES];
    }];
}

-(void)getResults{
    LLog(@"getResults");
    if (self.num > 5) {
        [self.timer invalidate];
        [self removeFromSuperview];
        return;
    }
    self.num ++;
}

-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}



@end
